39
class Solution {
    ListListInteger ret = new ArrayList();
    ListInteger tmp = new ArrayList();

    public ListListInteger combinationSum(int[] candidates, int target) {
        fun(candidates, target, candidates.length, 0, 0);
        return ret;
    }

    public void fun(int[] candidates, int target, int len, int i, int sum) {
        if (sum  target) {
            return;
        }
        if (sum == target) {
            ListInteger list = new ArrayList();
            list.addAll(tmp);
            ret.add(list);
            return;
        }
        for (; i  len; i++) {
            tmp.add(candidates[i]);
            fun(candidates, target, len, i, sum+candidates[i]);
            tmp.remove(tmp.size()-1);
        }
    }
}
汉诺塔问题
import java.util.*;

public class Main{
    public static void move(char i, char j) {
        System.out.println(i+"->"+j);
    }
    public static void hnt(int n, char i, char j, char k) {
        if (n == 1) {
            move(i,k);
            return;
        }
        hnt(n-1, i, k, j);
        move(i, k);
        hnt(n-1, j, i, k);
    }

    public static void main(String[] args) {

        hnt(3, 'a', 'b', 'c');
    }
}
实现一个方法 transform, 以数组为参数, 循环将数组中的每个元素 乘以 2 , 并设置到对应的数组元素上. 例如 原数组为 {1, 2, 3}, 修改之后为 {2, 4, 6}
import java.util.*;

public class Main{
    public static void transform(int[] arr) {
	if (arr == null){
            return;
        }
        for (int i = 0; i < arr.length; i++) {
            arr[i] *= 2;
        }
    }

    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6};
        System.out.println(Arrays.toString(arr));
        transform(arr);
        System.out.println(Arrays.toString(arr));
    }
}